package com.ketangpai.admin.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ketangpai.admin.entity.UserCourse;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserCourseDao extends BaseMapper<UserCourse> {
    @Select("select * from user_course where course_id=#{courseId}")
    List<UserCourse> getByCid(Integer courseId);

    @Select("select * from user_course where user_id=#{userId}")
    List<UserCourse> getById(Integer userId);
    @Select("select * from user_course where user_id=#{userId} and course_id=#{courseId}")
    UserCourse getByUserAndCourse(Integer userId,Integer courseId);
    @Delete("DELETE FROM user_course WHERE id=#{id}")
    boolean deleteById(Integer id);

    @Select("select * from user_course where type=1 and course_id=#{courseId}")
    List<UserCourse> getCourseStudentNumber(Integer courseId);

    @Select("select user_id from user_course where type!=0 and course_id=#{courseId}")
    List<Integer> getTeachersId(Integer courseId);

    @Select("select user_id from user_course where type=0 and course_id=#{courseId}")
    List<Integer> getStudentsId(Integer courseId);

    @Select("select * from user_course where type=0 and course_id=#{courseId}")
    List<UserCourse> getStudents(Integer courseId);

    @Delete("DELETE FROM user_course WHERE course_id=#{courseId}")
    boolean deleteByCourseId(Integer courseId);
}
